from django.core.files import storage
from django.conf import settings
# from fdfs_client.client import Fdfs_client
from fdfs_client.client import Fdfs_client, get_tracker_conf


# class FDFSStore(storage):
#     ''''''
#     def __init__(self, client_conf=None, base_url=None):
#         if client_conf is None:
#             self.client_conf = settings.FASTDFS_CLIENT_CONF
#         self.client_conf = client_conf
#         if base_url is None:
#             self.base_url = settings.NGINX_BASE_URL
#         self.base_url = base_url
#
#     def _open(self,name,mode='rb'):
#         pass
#
#     def _save(self, name, content):
#         '''保存文件时使用
#             @name:上传文件的名字
#             @content:包含上传内容的对象
#         '''
#         client = Fdfs_client(self.client_conf)
#
#         res = client.upload_by_buffer(content.read())
#         # dict
#         # {
#         #     'Group name': group_name,
#         #     'Remote file_id': remote_file_id,
#         #     'Status': 'Upload successed.',
#         #     'Local file name': '',
#         #     'Uploaded size': upload_size,
#         #     'Storage IP': storage_ip
#         # }
#         print('====================')
#         if res['Status'] != 'Upload successed.':
#             raise Exception('upload fast dfs failed!')
#
#         filename = res['Remote file_id']
#
#         return filename
#
#     def exists(self):
#         '''Django在save之前，判断文件名是否可用'''
#         return False
#
#     def url(self, name):
#         '''返回访问文件的url路径'''
#         return self.client_conf+name